<?php
class M_levels extends CI_Model {
	
	private $__table = 'levels';
	
	public function get_all_levels_array()
	{
		$query = $this->db->select(array('level_id','level_desc','level_code'))->get($this->__table);
		if($query->num_rows() > 0)
		{
			$result[''] ='-- Choose A Level --';
			foreach($query->result() as $q)
			{
				$result[$q->level_id] = $q->level_code.' | '.$q->level_desc;
			}
			return $result;
		}else{
			return FALSE;
		}
	}
	
	public function get_lesser_levels_array($lid=FALSE)
	{
		if($lid)
		{
			$query = $this->db->select(array('level_hierarchy'))->where('level_id', $lid)->get($this->__table);
			$rs = $query->row();
			
			$query = $this->db->select(array('level_id','level_desc','level_code'))->where('level_hierarchy >', $rs->level_hierarchy)->get($this->__table);
			if($query->num_rows() > 0)
			{
				$result[''] ='-- Choose A Level --';
				foreach($query->result() as $q)
				{
					$result[$q->level_id] = $q->level_code.' | '.$q->level_desc;
				}
				return $result;
			}else{
				return FALSE;
			}
		}else{
			$this->get_all_levels_array();
		}
	}
}
?>